package com.iknight.mgr.core.excel;

import org.apache.commons.fileupload.ProgressListener;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSession;
/*
 * @author JeryZym
 * @date 2018/1/3
 * 文件解析进度
 */
@Component
public class ParseProgressListener implements ProgressListener {
    private HttpSession session;

    public void setSession(HttpSession session) {
        this.session = session;
        ParseProgress parseProgress = new ParseProgress();
        session.setAttribute("status", parseProgress);
    }

    @Override
    public void update(long pBytesRead, long pContentLength, int pItems) {
        ParseProgress parseProgress = (ParseProgress) session.getAttribute("status");
        try {
            Thread.sleep(5);

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        parseProgress.setpBytesRead(pBytesRead);
        parseProgress.setpContentLength(pContentLength);
        parseProgress.setpItems(pItems);
    }
}
